import 'package:flutter/material.dart';
import 'package:flutter_anim_test/pigeons/messages.g.dart';
import 'package:flutter_anim_test/pigeons/pigeons_config.dart';
import 'package:flutter_anim_test/router.dart';
// import 'package:flutter_boost/flutter_boost.dart';

void main() {
  ///这里的CustomFlutterBinding调用务必不可缺少，用于控制Boost状态的resume和pause
  CustomFlutterBinding();
  PigeonsConfig.init();
  runApp(const MyApp());
}

///创建一个自定义的Binding，继承和with的关系如下，里面什么都不用写
class CustomFlutterBinding extends WidgetsFlutterBinding {}
// class CustomFlutterBinding extends WidgetsFlutterBinding with BoostFlutterBinding {}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    print("ddddddddddddddd");
    // return MaterialApp(
    //   initialRoute: "/home",
    //   (RouteSettings settings, String? uniqueId) {
    //     print("FlutterBoostApp routeFactory ${settings.name}");
    //     if (routers.containsKey(settings.name)) {
    //       return MaterialPageRoute(
    //         builder: routers[settings.name]!,
    //         settings: settings,
    //       );
    //     } else {
    //       return null;
    //     }
    //   },
    //   appBuilder: appBuilder,
    // );
    // return appBuilder(const MyHomePage(title: 'Flutter Demo Home Page'));
    return MaterialApp(
      title: 'Flutter Demo',
      routes: routers,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
        useMaterial3: true,
      ),

      ///必须加上builder参数，否则showDialog等会出问题
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }

  Widget appBuilder(Widget home) {
    return MaterialApp(
      title: 'Flutter Demo',
      routes: routers,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
        useMaterial3: true,
      ),

      ///必须加上builder参数，否则showDialog等会出问题
      builder: (_, __) {
        return home;
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          spacing: 10,
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            OutlinedButton(
                onPressed: () async {
                  print("aaaaaaaaa ${await PigeonsConfig.api.getHostLanguage()}");
                  //跳转页面
                  // Navigator.pushNamed(context, "/implicit");
                },
                child: Text("隐式动画")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/explicit");
                },
                child: Text("显示动画")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/flutter_animate");
                },
                child: Text("flutter_animate")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/canvas");
                },
                child: Text("canvas")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/native/message");
                },
                child: Text("原生交互")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/LineChart");
                },
                child: Text("LineChart")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/LineMaxDataChart");
                },
                child: Text("LineMaxDataChart")),
            FilledButton(
                onPressed: () {
                  // BoostNavigator.instance
                  //     .push("/native/page1", withContainer: true) // Native页面路由
                  //     .then((value) => print('retval:$value'));
                },
                child: Text("原生页面")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/custom/widget");
                },
                child: Text("自定义组件")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/CollapsingToolbarPage");
                },
                child: Text("CollapsingToolbarPage")),
            FilledButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/ScrollTopStickyPage");
                },
                child: Text("ScrollTopStickyPage")),
          ],
        ),
      ),
      // floatingActionButton: FloatingActionButton(
      //   onPressed: _incrementCounter,
      //   tooltip: 'Increment',
      //   child: const Icon(Icons.add),
      // ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
